<template>
    <view class="nickname">
        <view class="nick">
            <view class="nc">
                昵称
            </view>
            <input type="text" v-model="nameval" placeholder="请输入修改昵称（最多6个字）" maxlength="6"/>
        </view>
        <view class="preservation" @click="subfn">
            保存
        </view>
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
    export default{
        data(){
            return {
                nameval:''
            }
        },
        onLoad() {
            uinfo = uni.getStorageSync('userInfo');
 
        },
        methods:{
            subfn(){
                uni.showLoading({
                    mask:true
                });
                request.postMember('/user/info/updateBasicInfo', {
                    userId: uinfo.userId,
                    nickname :this.nameval
                }).then(res=>{
                    console.log(res)
                    if(res.code=='200'){
                        uni.hideLoading();
                        uni.showToast({
                            icon: "none",
                            title: '更换成功',
                        });
                        uni.redirectTo({
                            url: '/pages/persondata/persondata'
                        });
                    }else{
                        uni.hideLoading();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            }
        }
    }
</script>

<style>
    .nickname{
        background-color: #F5F5F5;
        height: 90vh;
        padding: 46rpx 0 0 0;
    }
    .nick{
        width: 710rpx;
        height: 110px;
        background: #FFFFFF;
        border-radius: 6px;
        margin: 0 auto 0;
    }
    
    .nc{
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 24px;
        color: #333333;
        margin: 0px 0 0 10px;
        padding: 20px 0 0 0;
    }
    .nick input{
        width: 400rpx;
        height: 40rpx;
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 24px;
        margin: 15px 0 0 10px;
    }
    
    .preservation{
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 38px;
        color: #FFFFFF;
        width: 355px;
        height: 38px;
        background: #7F6AC3;
        border-radius: 19px;
        text-align: center;
        margin: 100px auto 0;
    }
</style>
